<script setup name="cusLayout">
import CusNav from "@/components/cus-nav.vue";
import { computed, reactive, ref } from "vue";
import store from "@/store";
import router from "@/router";
let nowRouterName = reactive(null)
const goRouter = (data) => {
  router.push(data.fullPath)
}
const delRouter = (index) => {
  store.commit('delRouterHistory', index)
}
let routerHistory = reactive([])
routerHistory = computed(() => {
  return store.state.routerHistory
})
nowRouterName = computed(() => {
  return store.state.nowRouterName
})
console.log(routerHistory)
</script>

<template>
  <div class="layout">
    <div class="layout_nav">
      <cus-nav></cus-nav>
    </div>
    <div class="layout_body">
      <div class="layout_body_tab">
        <div class="one_tab" v-for="(data, index) in routerHistory"
          :class="[nowRouterName === data.name ? 'nowRouter' : 'noRouter']" :key="index">
          <div class="one_tab_name" @click="goRouter(data)">{{ data?.meta?.title }}</div>
          <el-icon class="one_tab_icon" v-if="routerHistory.length !== 1" @click="delRouter(index)">
            <Close />
          </el-icon>
        </div>
      </div>
      <div class="layout_body_content">
        <div class="layout_body_view">
          <slot></slot>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss">
.layout {
  .el-tabs__header {
    margin: 0;
  }
}
</style>
<style scoped lang="scss">
.layout {
  width: 100%;
  height: 100%;
  display: flex;
  display: -moz-flex;
  display: -webkit-flex;

  .layout_nav {
    width: 200px;
    height: 100%;
    background-color: #ffffff;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    border-right: 1px solid #eeeeee;
  }

  .layout_body {
    width: calc(100% - 200px);
    height: 100%;

    .layout_body_tab {
      width: 100%;
      height: 36px;
      overflow: hidden;
      display: flex;
      display: -webkit-flex;
      display: -moz-flex;
      background-color: white;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);

      .one_tab {
        width: max-content;
        flex-basis: max-content;
        flex-shrink: 0;
        box-sizing: border-box;
        padding: 0 15px 0;
        color: #6a6666;
        font-size: 12px;
        height: 36px;
        display: flex;
        display: -webkit-flex;
        display: -moz-flex;
        align-items: center;
        transition: width 0.5s, flex-basis 0.5s;
        -webkit-transition: width 0.5s, flex-basis 0.5s;
        /* Safari */

        .one_tab_name {
          margin-right: 10px;
          cursor: pointer;
        }

        &:hover {
          .one_tab_icon {
            display: block;
          }
        }

        .one_tab_icon {
          cursor: pointer;
          display: none;

          &:hover {
            color: red;
          }
        }
      }
    }

    .layout_body_content {
      height: calc(100% - 36px);
      // height: 100%;
      width: 100%;
      box-sizing: border-box;
      padding: 10px;
    }

    .layout_body_view {
      width: 100%;
      height: 100%;
    }
  }
}

.nowRouter {
  color: #ffffff !important;
  background-color: cornflowerblue;
}

.noRouter {
  background-color: #ffffff;
}
</style>